function [RET] = non_max_supression(IMG,PHASE,T)

[height width] = size(IMG);

for i=1:height
	for j=1:width
		if (IMG(i,j) >= T)
			if ( (i == 1) | (i == height) | (j == 1) | (j == width))
				RET(i,j) = 0;
			else
				if (PHASE(i,j) == 0)
					check_1 = IMG(i,j+1);
					check_2 = IMG(i,j-1);
				elseif (PHASE(i,j) == 45)	
					check_1 = IMG(i-1,j+1);
					check_2 = IMG(i+1,j-1);
				elseif (PHASE(i,j) == 90)	
					check_1 = IMG(i+1,j);
					check_2 = IMG(i-1,j);
				else
					check_1 = IMG(i-1,j-1);
					check_2 = IMG(i+1,j+1);
				end

				if ( (IMG(i,j) >= check_1) & (IMG(i,j) >= check_2))
					RET(i,j) = 1;
				else
					RET(i,j) = 0;
				end

			end
			
		else
			RET(i,j) = 0;
		end
	end
end
